//
//  FDBarcodeController.m
//  FamousDoctorOnline
//
//  Created by 丁鼎 on 16/7/11.
//  Copyright © 2016年 wszyxc. All rights reserved.
//

#import "FDBarcodeController.h"
#import "HMScannerController.h"

@interface FDBarcodeController ()

@property (nonatomic,strong)UIImageView *image;

@property (nonatomic,strong)UILabel *result;

@end

@implementation FDBarcodeController

-(void)viewDidLoad
{
    [super viewDidLoad];
    [self setupUI];
    [self setupCode];
    
    
    
}


-(void)setupUI
{
    
    UIImageView *image =[[UIImageView alloc]init];
    [self.view addSubview:image];
    self.image = image;
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.width.height.mas_equalTo(150);
        make.centerX.equalTo(self.view.mas_centerX);
        make.centerY.equalTo(self.view.mas_centerY);
    }];
    
    UILabel *result = [UILabel new];
    [self.view addSubview:result];
    self.result = result;
    [result mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.image.mas_centerX);
        make.top.mas_equalTo(self.image.mas_bottom).offset(10);
        
    }];
    
    UIBarButtonItem *sao = [[UIBarButtonItem alloc]initWithTitle:@"扫一扫" style:UIBarButtonItemStyleDone target:self action:@selector(clickScan)];
    [sao setTintColor:[UIColor whiteColor]];
    self.navigationItem.rightBarButtonItem = sao;
    
}

-(void)setupCode{
    NSString *string = @"呵呵哒";
    UIImage *image = [UIImage imageNamed:@"product_img_logo_nor.png"];
    
    [HMScannerController cardImageWithCardName:string avatar:image scale:0.2 completion:^(UIImage *image) {
        self.image.image = image;
    }];
}

-(void)clickScan
{
    NSString *cardName = @"天涯刀哥 - 傅红雪";
    UIImage *avatar = [UIImage imageNamed:@"avatar"];
    
    HMScannerController *scanner = [HMScannerController scannerWithCardName:cardName avatar:avatar completion:^(NSString *stringValue) {
        self.result.text = stringValue;
    }];
    
    [scanner setTitleColor:[UIColor whiteColor] tintColor:[UIColor greenColor]];
    
    [self showDetailViewController:scanner sender:nil];
    
}

@end
